﻿package plugin.gameHall.game.vplan
{
    import com.core.*;
    import flash.events.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.platform.*;
    import uiresource.vplan.*;
    import view.mornExtends.*;
    import vo.*;

    public class DengJiLiBaoCtrl extends DengJiLiBaoUI implements IVplan
    {
        private var _curlevel:int;

        public function DengJiLiBaoCtrl()
        {
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            return;
        }// end function

        private function itemHandler(param1:Component, param2:int) : void
        {
            var _loc_6:Array = null;
            var _loc_3:* = param1.dataSource.level;
            if (_loc_3 <= this._curlevel)
            {
                _loc_6 = ModelProxy.getValue("data", "vlevelGift");
                if (_loc_6 && _loc_6.indexOf(_loc_3) >= 0)
                {
                    (param1.getChildByName("lqBtn") as Button).visible = false;
                    (param1.getChildByName("lingqu") as Image).visible = true;
                }
                else
                {
                    (param1.getChildByName("lingqu") as Image).visible = false;
                    (param1.getChildByName("lqBtn") as Button).visible = true;
                    (param1.getChildByName("lqBtn") as Button).label = "可领取0/1";
                }
            }
            else
            {
                (param1.getChildByName("lqBtn") as Button).visible = false;
            }
            var _loc_4:int = 1;
            while (_loc_4 <= 3)
            {
                
                if (_loc_3.toString().length >= _loc_4)
                {
                    (param1.getChildByName("lv" + _loc_4) as UrlImage).url = "cs2_vplan/" + _loc_3.toString().charAt((_loc_4 - 1)) + ".png";
                    (param1.getChildByName("lv" + _loc_4) as UrlImage).visible = true;
                }
                else
                {
                    (param1.getChildByName("lv" + _loc_4) as UrlImage).visible = false;
                }
                _loc_4++;
            }
            (param1.getChildByName("lqBtn") as Button).removeEventListener(MouseEvent.CLICK, this.lqbtnClickHandler);
            (param1.getChildByName("lqBtn") as Button).addEventListener(MouseEvent.CLICK, this.lqbtnClickHandler);
            var _loc_5:* = int(param1.dataSource.vgift);
            this.showItem(param1.getChildByName("itemList") as List, _loc_5);
            return;
        }// end function

        protected function lqbtnClickHandler(event:MouseEvent) : void
        {
            PlatformSender._11360Antivirus(((event.currentTarget as Button).parent as Component).dataSource.level);
            return;
        }// end function

        private function showItem(param1:List, param2:int) : void
        {
            var _loc_8:String = null;
            var _loc_9:Array = null;
            var _loc_10:Object = null;
            var _loc_3:* = ConfigDictionary.data.box;
            var _loc_4:* = ConfigDictionary.data.item;
            var _loc_5:Array = [];
            var _loc_6:* = (_loc_3[param2].items as String).split(";");
            var _loc_7:int = 0;
            while (_loc_7 < _loc_6.length)
            {
                
                _loc_8 = _loc_6[_loc_7];
                _loc_9 = _loc_8.split("-");
                if (_loc_9.length >= 4)
                {
                    if (_loc_9[3] != 2 && _loc_9[3] != ModelProxy.getValue("data", "user.sex"))
                    {
                        ;
                    }
                }
                if (_loc_9.length >= 5)
                {
                    if (_loc_9[4] != 0 && _loc_9[4] != ModelProxy.getValue("data", "user.career"))
                    {
                        ;
                    }
                }
                _loc_10 = ItemObject.create(_loc_4[_loc_9[0]]);
                _loc_10.count = _loc_9[1];
                _loc_5.push(_loc_10);
                _loc_7++;
            }
            param1.array = _loc_5;
            param1.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param1 && param1.dataSource)
            {
                (param1 as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

        public function showplan() : void
        {
            this.visible = true;
            this.update();
            return;
        }// end function

        public function update() : void
        {
            var _loc_4:String = null;
            var _loc_5:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "configs.vlevelgift");
            var _loc_2:Array = [];
            var _loc_3:* = UserData.getUserData("level");
            for (_loc_4 in _loc_1)
            {
                
                if (int(_loc_4) != 1)
                {
                    _loc_5 = {level:_loc_4, vgift:_loc_1[_loc_4]};
                    _loc_2.push(_loc_5);
                }
                if (int(_loc_4) <= _loc_3 && this._curlevel < int(_loc_4))
                {
                    this._curlevel = int(_loc_4);
                }
            }
            _loc_2.sortOn("level", Array.CASEINSENSITIVE);
            list.array = _loc_2;
            list.renderHandler = new Handler(this.itemHandler);
            return;
        }// end function

        public function closeplan() : void
        {
            this.visible = false;
            return;
        }// end function

    }
}
